package com.tests;

import be.ac.ulg.montefiore.run.jahmm.ObservationReal;
import com.utils.SequenceIterator;
import junit.framework.TestCase;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: bigmar
 * Date: 12/9/14
 * Time: 11:33 AM
 * To change this template use File | Settings | File Templates.
 */
public class TestSequenceIterator extends TestCase
{
    public void test1Obj()
    {
        List<List<ObservationReal>> seqs=new ArrayList();
        List<ObservationReal> seq=new ArrayList();
        seq.add(new ObservationReal(0.));
        seqs.add(seq);

        verifyData(seqs, 1, new boolean[]{true});
    }

    public void test2Obj()
    {
        List<List<ObservationReal>> seqs=new ArrayList();
        List<ObservationReal> seq=new ArrayList();
        seq.add(new ObservationReal(0.));
        seq.add(new ObservationReal(1.));
        seqs.add(seq);
        verifyData(seqs, 2, new boolean[]{true, false});
    }

    public void test2Seqs()
    {
        List<List<ObservationReal>> seqs=new ArrayList();
        List<ObservationReal> seq=new ArrayList();
        seq.add(new ObservationReal(0.));
        seq.add(new ObservationReal(1.));
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(2.));
        seq.add(new ObservationReal(3.));
        seqs.add(seq);

        verifyData(seqs, 4, new boolean[]{true, false, true, false});
    }

    public void test3SeqsOneEmpty()
    {
        List<List<ObservationReal>> seqs=new ArrayList();
        List<ObservationReal> seq=new ArrayList();
        seq.add(new ObservationReal(0.));
        seq.add(new ObservationReal(1.));
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(2.));
        seq.add(new ObservationReal(3.));
        seqs.add(seq);

        verifyData(seqs, 4, new boolean[]{true, false, true, false});
    }
    public void testManyEmpty()
    {
        List<List<ObservationReal>> seqs=new ArrayList();
        List<ObservationReal> seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(0.));
        seq.add(new ObservationReal(1.));
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(2.));
        seq.add(new ObservationReal(3.));
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);

        verifyData(seqs, 4, new boolean[]{true, false, true, false});
    }

    public void testManyEmptyOneEach()
    {
        List<List<ObservationReal>> seqs=new ArrayList();
        List<ObservationReal> seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(0.));
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(1.));
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(2.));
        seqs.add(seq);
        seq=new ArrayList();
        seq.add(new ObservationReal(3.));
        seqs.add(seq);
        seq=new ArrayList();
        seqs.add(seq);

        verifyData(seqs, 4, new boolean[]{true, true, true, true});
    }
    private void verifyData(List<List<ObservationReal>> seqs, int number, boolean[] isNewSequence)
    {
        SequenceIterator sequenceIterator=new SequenceIterator(seqs, number);

        for (double i=0; i<number; ++i)
        {
            assertTrue(sequenceIterator.hasNext());
            assertEquals(isNewSequence[(int)i], sequenceIterator.isNewSequence());
            assertEquals(i,((ObservationReal)sequenceIterator.next()).value);

        }
    }
}
